package com.forcetools.utils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.sforce.soap.metadata.Package;
import com.sforce.soap.metadata.PackageTypeMembers;

public class PackageHelper {
	private static Map<String,Package> pkgMasterMap;
	static{
		pkgMasterMap = new HashMap<String,Package>();
	}
	public static Package getPackageConfig(String configName) throws Exception{
		if(!pkgMasterMap.containsKey(configName)){
			Package pkgConfig = new Package();
			String pkgMbrs = PropertyConfigUtils.getProperty("package_config",configName, "includeComponents");
			String apiVerTxt = PropertyConfigUtils.getProperty("package_config",configName, "apiVersion");
			//double apiVerNbr = Double.valueOf(PropertyConfigUtils.getProperty("package_config",configName, "apiVersion"));
			ArrayList<PackageTypeMembers> pkgMbrList= new ArrayList<PackageTypeMembers>();
			for(String componentName:pkgMbrs.split(",")){
				PackageTypeMembers mbr= new PackageTypeMembers();
				mbr.setMembers(new String[]{"*"});
				mbr.setName(componentName);
				pkgMbrList.add(mbr);
			}
			pkgConfig.setTypes(pkgMbrList.toArray(new PackageTypeMembers[]{}));
			pkgConfig.setVersion(apiVerTxt);
			pkgMasterMap.put(configName, pkgConfig);
		}
		return pkgMasterMap.get(configName);
	}
}
